-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce TypelessStructLiteralArg
and NewConstructorArg
interfaces
#183
Conversation
I have concerned about there are undocumented differences in
I believe it is a syntax for proto extensions and it is not yet available in Cloud Spanner, but I think these semantics are not same. It may be a reason to distinguish between
|
This difference is natural because:
|
IMHO, when |
Personally I think it is acceptable to generalize them temporarily, even if their semantics are not same,
I think it can't be a general name because it is |
I understood. We can add another interface when it is needed. |
IMHO,
(There are many variants.) |
ast/ast.go
Outdated
Values []*ExprAsName | ||
} | ||
|
||
// ExprAsName is value with optional name in typeless struct literal or new constructor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is not only for typeless struct literal and new constructor.
We can encourage to use this struct for any expr [AS ident]
syntax, without semantic implications.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can update the document anytime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means that this struct is added only for NewConstructorArg
and TypelessStructValue
in this PR context and we need to discuss to change this struct semantics in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From this conversation, it sounds like you don't intend to widely recommend the use of this struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought:
TypelessStructValue
andNewConstructorArg
is not same abstraction, but have common concrete structure.- Concrete structure will able to be reused without modification.
- IMO, currently
ExprAsName
is no strong reason to be introduced.
Finally, I conclude there is no better name for the struct Therefore, we introduce new interfaces |
AsExpr
instead of TypelessStructValue
and NewConstructorValue
TypelessStructLiteralArg
and NewConstructorArg
interfaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel it is natural to introduce these interfaces and use ExprArg
and Alias
.
I have not noticed their SelectItem
implementation can be used to implement them.
I agree their implementations are better than my original PRs.
parser.go
Outdated
@@ -479,22 +479,26 @@ func (p *Parser) parseSelectItem() ast.SelectItem { | |||
} | |||
} | |||
|
|||
func (p *Parser) tryParseAsAlias() *ast.AsAlias { | |||
func (p *Parser) tryParseAsAlias(requiredAs bool) *ast.AsAlias { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like p.tryParseAsAlias( /* requiredAs */ false)
is a little difficult to write.
Can't we introduce two method for requiredAs=true
and requiredAs=False
? (like (tryParseAsAliasAsRequired
and tryParseAsAliasAsOptional
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tryParseAsAliasAsRequired
seems like a strange name to someone unfamiliar with this project (e.g. twice As
looks like typo, and try
and required
seem contradictory), and it is hard to guess what the method does. By making the explicit argument, it is clear that the method parses AS name
as possible, and the comment makes it clear that the argument gives the required AS
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought:
twice
As
looks like typo
I think that the current AsAlias
([AS] alias
) may be better to be called as Alias
, and the current Alias
(expr [AS] alias
, alias required) can be called as ExprWithAlias
or AliasedExpr
.
tryParseAliasAsRequired
and tryParseAliasAsOptional
are felt better.
the comment makes it clear that the argument gives the required AS.
I think maintaining /* requiredAs */
comment is harder because it can't be assisted by go-lsp gopls or IDEs, and it is also strange to someone(me) unfamiliar with this project. At least, it must be noted in doc comment of tryParseAsAlias()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tryParseAliasAsRequired
also seems strange to me because As
looks like a usual preposition, and try
and required
have conflicting meanings.
I think that Alias
is the identifier after AS
, not the AS name
itself. In that sense, I think that the current Alias
should be changed to AliasedExpr
, but I do not agree with naming AsAlias
as Alias
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tryParseAliasAsRequired
also seems strange to me becauseAs
looks like a usual preposition, andtry
andrequired
have conflicting meanings.
It means they can be better if the subject of "required" or "optional" is unambiguous.
The subject is AS
keyword, so they can be called as like tryParseAsAliasRequireKeyword
, tryParseAsAliasOptionalKeyword
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ambiguous enough that there are multiple methods to parse a particular struct, and I don't think it's a good idea to distinguish them by method names. If it really should be parsed by multiple methods, we should introduce multiple structs, but I don't think in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ambiguous enough that there are multiple methods to parse a particular struct
I agree structs and methods should be one by one.
In other languages, it may be a usecase of named parameter which is missing in Go.
In Go, it may be better to introduce typed constant with enum semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, because of code jumps and editor popups, I decided to remove the /* requiredAs */
comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have agreed about tryParseAsAlias()
, so it is just my thought.
I think that
Alias
is the identifier afterAS
, not theAS name
itself. In that sense, I think that the currentAlias
should be changed toAliasedExpr
, but I do not agree with namingAsAlias
asAlias
.
SQL has common structure "alias, which is optionally prefixed by AS
", and they are safe to unparse always with AS
in GoogleSQL.
I prefer to call it Alias
than AsAlias
because someones have coding guideline which prefer to omit AS
.
As far as I know, AS
of table alias is often omitted. (Probably due to Oracle's past not allowing AS
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name Alias
has less information than the name AsAlias
, so I don't think it should be changed proactively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we have finished discussions and tryParseAsAlias
with typed enum resolves our concernings.
Thank you for finishing my PRs.
LGTM!
…TypedStructLiteral
Also, this fixes a `AsAlias.As` position bug.
a2a7a36
to
8ea0e53
Compare
Close #119
Close #177
TypelessStructValue
(#177) andNewConstructorValue
(#119) share their struct shapes. Then, this PR introduces a new struct namedAsExpr
forexpression AS name
-kind values and replaces them with it.I believe this is not a hasty generalization because these struct shapes are exactly the same, and they are used for common semantics. However, I'm not sureAsExpr
is the best name. If you have a better name, please tell me it!Thank you.See #183 (comment).